package com.yy.controller;

import com.yy.common.Resault;
import com.yy.domain.User;
import com.yy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("member")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 查询用户信息
     * @param userId
     * @return
     */

    @GetMapping("/getMember")
    public User getMember(@RequestParam("userId") Integer userId){
        return this.userService.getMember(userId);
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/updateMember")
    public Resault updateMember(@RequestBody User user){
        int row=this.userService.updateMember(user);
        if (row<=0){
            return new Resault(-1,"修改失败");
        }
        return new Resault(200,"修改成功");
    }
    /**
     * 接口说明：用户在使用单车之前，需要先充值，充值金额单位为元
     * 请求方式：POST
     * 请求url：/member-service/member/recharge
     */
    @PostMapping("/recharge")
    public Resault recharge(Integer userId,Integer money) throws Exception {
        int row=this.userService.dorecharge(userId,money);
        if (row<=0){
            return new Resault(-1,"充值失败","");
        }
        return new Resault(200,"充值成功","");
    }
}
